/*
 * Timer.cpp
 *
 *	Author: stravant
 *	Description:
 *		
 */

#include "Timer.h"

namespace tbt {

Timer::Timer(): mTime(Time::Now()) {}
Timer::~Timer() {}

void Timer::reset() {
	mTime = Time::Now();
}

TimeDelta Timer::elapsed() const {
	return Time::Now() - mTime;
}

//////////////////////////////

Ticker::Ticker(Ref<EventLoop> eventLoop) {
	eventLoop->addTask(new Ticker_Task(this));
}

Ticker::~Ticker() {
	if (mTask)
		mTask->kill();
}

////////////////////////////////

TickerPeriodic::TickerPeriodic(TimeDelta period, Ref<EventLoop> eventLoop):
		Ticker(eventLoop), mPeriod(period), mLastTick(Time::Now()) {
	start();
}

TickerPeriodic::~TickerPeriodic() {}

void TickerPeriodic::tick(Time t) {
	if (mIsRunning) {
		while (t > (mLastTick+mPeriod)) {
			mLastTick += mPeriod;
			periodicTick(mLastTick);
		}
	}
}

////////////////////////////////



}














